/**
 * 신고서, 내역서 출력 - 제출서류안내(필수) 
 **/
package com.skt.common_hr.yearadjustment.model
{

	import com.skt.common_hr.common.puremvc.CommonProxy;
	import com.skt.common_hr.yearadjustment.YearAdjustmentFacade;
	
	import flash.net.URLVariables;
	
	import mx.collections.ArrayCollection;
	import mx.rpc.events.FaultEvent;
	import mx.rpc.events.ResultEvent;
	import mx.utils.ObjectUtil;
	

	public class PresentReportProxy extends CommonProxy
	{
		public static const NAME:String = "PresentReportProxy";
		public var msgStr:String;
		public var sYear:String;
		
		public var present:URLVariables = new URLVariables();
		
		public var resultList:ArrayCollection = new ArrayCollection;
		
		public function PresentReportProxy(data:Object=null)
		{
			super(NAME, data);
		}
		
		/**
		 * data load를 수행
		 * 		- DataLoader 를 생성하고 Import Parameter 객체를 생성, RFC를 호출
		 * 
		 * @param pernr 사번
		 * @return void
		 */
		public function load(pernr:String, year:String):void
		{
			var param:Object = new Object();						  

			param["I_PERNR"] = pernr;
			param["I_YEAR"] = year;
			sYear = year;
			
			loadData("Z_HR_YEA_DOCUMENT", param, result, fault);
		}
		
		/**
		 * 서버에서 정상적으로 리턴된 결과를 처리
		 * 
		 * @param
		 * @return void
		 */
		public function result(event:ResultEvent):void
		{
			var retCode:Number = event.result["RETCODE"];
			var retText:String = event.result["RETTEXT"];
			msgStr = retText;
			
			if(retCode==0) {
				setResult(event.result["T_ITAB"],event.result["E_HOUSE"]);
				facade.sendNotification(YearAdjustmentFacade.LOAD_PRESENT_REPORT_COMPLETE, this);
			}
			else {
				facade.sendNotification(YearAdjustmentFacade.LOAD_PRESENT_REPORT_FAILED, this);
			}
			
		}
		
		/**
		 * 서버에서 오류가 발생했을 처리
		 * 
		 * @param
		 * @return void
		 */
		private function fault(event:FaultEvent):void
		{
			msgStr = event.fault.faultString;
			facade.sendNotification(YearAdjustmentFacade.LOAD_PRESENT_REPORT_FAILED, this);
		}
		
		private function setResult(result:ArrayCollection,  E_HOUSE:String):void
		{
			resultList = result;
			
			present["DOCUM1"]="";
			present["DOCUM2"]="";
			present["resultList"]=result;
			present["E_HOUSE"]=E_HOUSE;
			
			for(var i:* in result.source){
				var item:Object = result.source[i];
				present["DOCUM1"] += item["DOCUM1"]+"|";
				present["DOCUM2"] += item["DOCUM2"]+"|";
			}
		}
		
	}
}